import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Solution {
    //变味词组
    public List<List<String>> groupAnagrams(String[] strs) {
        //将转换后的字符串作为哈希的键，源字符串添加到list数组中
        int n = strs.length;
        HashMap<String, List<String>> map = new HashMap();
        for(int i = 0; i < n; i++) {
            char[] str = strs[i].toCharArray();
            Arrays.sort(str);
            String key = new String(str);
            List<String> list = map.getOrDefault(key,new ArrayList<>());
            list.add(strs[i]);
            map.put(key,list);
        }
        return new ArrayList<>(map.values());
    }
}
